<template>
  <div class="post">
    <!-- 头部 -->
    <myheader>
      <template #left>
        <van-icon name="arrow-left" @click="$router.go(-1)" />
      </template>
      <template #center>
        <span>我的关注</span>
      </template>
    </myheader>

    <myPostList
      v-for="item in list"
      :key="item.id"
      :list="item"
      @unpost="del"
    ></myPostList>
  </div>
</template>

<script>
import myheader from "@/components/myheader";
import myPostList from "@/components/myPostList";
import { userfollows, unfollow } from "@/api/user";
import axios from "@/utils/request";
export default {
  data() {
    return {
      list: {},
    };
  },
  components: {
    myheader,
    myPostList,
  },
  async mounted() {
    let res = await userfollows();
    console.log(res);

    //this.list = res.data.data;
    this.list = res.data.data.map((v) => {
      v.head_img = axios.defaults.baseURL + v.head_img;
      //改造后返回整个对象（每一条数据）
      return v;
    });
  },
  methods: {
    async del(id) {
      console.log(id);
      //取消关注
      //this.list = this.list.slice(0, 1);
      //发送请求
      let res = await unfollow(id);
      this.$toast.success(res.data.message);
      //刷新页面
      //location.reload();
      this.list = this.list.filter((v) => {
        return v.id != id;
      });
    },
  },
};
</script>

<style>
</style>